using System;
using System.Collections.Generic;

namespace Parking
{
	public class Parking
	{		
		public Parking (int pNbPlacesMax)
		{
			liste_acces = new List<Acces>();
			liste_tickets = new List<Ticket>();
			nbPlacesTotales = pNbPlacesMax;
		}

		public int nbPlacesRestantes {
			get { return nbPlacesTotales - nbPlacesOccupees; }
		}

		public int nbPlacesTotales {
			get; private set;
		}

		public int nbPlacesOccupees {
			get { return liste_tickets.Count; }
		}
		
		public List<Acces> liste_acces {
			get; private set;
		}
		
		public List<Ticket> liste_tickets {
			get; private set;
		}
		
		public Ticket garerVoiture (Voiture v)
		{
			if (nbPlacesRestantes <= 0) {
				return null;
			} else {
				var ticket = new Ticket ();
				liste_tickets.Add(ticket);
				
				foreach (Acces a in liste_acces) {
					foreach (Borne b in a.liste_bornes) {
						b.maj_label();
					}
				}
				return ticket;
			}
		}
		
		public void ajouterAcces(Acces a) {
			liste_acces.Add(a);
		}
		
		public Ticket reprendreVoiture (int pNumeroTicket)
		{
			foreach (Ticket t in liste_tickets) {
				if (t.numero == pNumeroTicket) {
					liste_tickets.Remove (t);
					foreach (Acces a in liste_acces) {
						foreach (Borne b in a.liste_bornes) {
							b.maj_label();
						}
					}
					return t;
				}
			}
			return null;
		}
	}
}
